import Mock from "mockjs";
import qs from "querystring";

Mock.mock(/^\/api\/message\/?(\?.+)?$/, "get", (opt) => {
  const query = qs.parse(opt.url);

  return Mock.mock({
    code: 0,
    msg: "",
    data: {
      total: 35,
      [`rows|${query.limit || 10}`]: [
        {
          id: "@guid",
          nickname: "@cname",
          content: "@cparagraph(1,10)",
          createDate: "@datetime",
          avatar: "@image('30x30','#070','#fff','@cname')",
        },
      ],
    },
  });
});

Mock.mock("/api/message", "post", {
  code: 0,
  msg: "",
  data: {
    id: "@guid",
    nickname: "@cname",
    content: "@cparagraph(1,10)",
    createDate: "@datetime",
    avatar: "@image('30x30','#070','#fff','@cname')",
  },
});
